﻿// JScript 文件
// 全局变量定义
var version = "v0.1.0.0"
var ie; // 判断系统是否IE
var opear = window.navigator.userAgent.indexOf("Opear") > 0 ? true : false;
var DownloadProgressLock; // 本浏览器下载进度锁
var BatchTestInProgressLock = false; // 批量测试进行中
var NextOperation = 0; // 下一次运行的测试，参考OperationText定义
var ScoreArray = new Array(); // 下载成绩的矩阵，内放置成绩矩阵 构成伪二维数组
var LengthArray; // 下载长度的预定数组(改2维...)
var LastSpeed = Number.POSITIVE_INFINITY; // infinity 无穷大，最近一次下载速度, In KByte/s
var LastTimeCost = 0; // millisecond 最近一次下载耗时
var CurrentXmlHttp; // 当前运行的XmlHttp指针
var req; // 改为全局，因此楼上的指针作废...
var CurrentTimerId; // 当前TimerID userd by XmlHttp
var GraphID = 0; // 图片ID
var KiloByte; // 定义千字节(1024 Bytes)
var KiloByteTimes256; // 定义千字节(256*1024 Bytes)
var LengthArray_MaxLength; // LengthArray.Length 最大大小
var startT; // XmlHttpRequest 开始时间
var InteractingCount; // S3 Interact 的计数

// HTML 元素 ID
var LogOutput_ID = "logoutput";
var ButtonUnitTest_ID = "BtnUnitTest";
var DownloadLength_ID = "DownloadLength";
var UploadLength_ID = "UploadLength";
var msecond_id = "msecondTest";
var speed_id = "SpeedTest";
var MaxTimeout_ID = "MaxTimeout";
var ButtonBatchTest_ID = "BtnBatch";
var BatchDownloadNoticer_ID = "BatchDownloadNoticer";
var historyGraph_ID = "historyGraph";
var progress_contain_ID = "progress_contain";
var progress_bar_ID = "progress_bar";
var HrefDisplayLog_ID = "HrefDisplayLog";
var userip_ID = "userip";
var browser_ID = "browser";
var system_ID = "system";
var NativeXMLHttpRequest_ID = "NativeXMLHttpRequest";
var ServiceURL_ID = "ServiceURL";
var BatchTestType_ID = "BatchTestType";

var NoticeText = new Array(
    "",
    "自动测试程序进行中...为保证测试结果相对准确，请勿同时运行其它网络应用。",
    "自动测试程序因单次测试超时而停止。",
    "自动测试程序成功完成所有测试",
    "自动测试程序因用户干预而中断"
    );
var UnitTestNoticeText = new Array(
    "",
    "单元测试进行中...为保证测试结果相对准确，请勿同时运行其它网络应用。",
    "单元测试程序因超时而停止。",
    "单元测试程序成功完成",
    "单元测试程序因用户干预而停止"
    );
var BatchCmdText = new Array(
    "",
    "批量测试",
    "中止批量测试",
    "单元测试",
    "中止单元测试"
    );
var BatchCmdScript = new Array(
    "",
    function () { AutomaticTestInit(); return false; },
    function () { AutomaticTestStopByUser(); return false; },
    function () { download(); return false; },
    function () { StopDownloadByUser(); return false; }
    );
var DownloadIMGText = new Array(
    "",
    "正在下载图片...",
    "图片服务未找到",
    "图片被缓存",
    "图片服务未定义错误",
    "速度图"
    );
var OperationText = new Array(
    "Download Only",
    "Upload Only",
    "Download & Upload"
    );

// 全局函数定义
function msieversion() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE");
    if (msie > 0)
        return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)));
    else
        return 0;
}

//function download(DownloadLength_ID, UploadLength_ID, msecond_id, speed_id)
function download() {
    if (DownloadProgressLock) return false; // 并发检查锁

    var DownloadLength = document.getElementById(DownloadLength_ID);
    var UploadLength = document.getElementById(UploadLength_ID);
    var SendData = ""; // 上传用数据包

    var DownloadLengthKByte = Math.min(100000, parseInt(DownloadLength.value, 10));    // 下载大小，千字节
    var UploadLengthKByte = Math.min(4000, parseInt(UploadLength.value, 10));    // 上载大小，千字节
    var frm = document.forms[0];

    //var url = "Download.aspx?DownloadLength=" + DownloadLengthKByte;  //GET
    var url = document.getElementById(ServiceURL_ID).value;      // POST

    var msecond = document.getElementById(msecond_id);
    var speed = document.getElementById(speed_id);
    var logoutput = document.getElementById(LogOutput_ID);
    var ButtonUnitTest = document.getElementById(ButtonUnitTest_ID);

    //var InteractingCount=0;

    var start;
    //var loadedT,startT;

    InteractingCount = 0; // S3的计数

    DownloadLength.value = DownloadLengthKByte;
    UploadLength.value = UploadLengthKByte;

    // 赶在统计时间之前，获取足够大的SendData内容
    for (var i = 0; i < Math.floor(UploadLengthKByte / 256); i++)
        SendData += KiloByteTimes256;

    for (var i = 0; i < UploadLengthKByte % 256; i++)
        SendData += KiloByte;

    //初始化继续延后
    //start=new Date();
    //var startT=start.getTime();

    //var req = new XMLHttpRequest();
    req = new XMLHttpRequest();  // 改为全局

    if (req) {
        req.onreadystatechange = statechange_callback;

        try {
            req.open('POST', url, true);
            // 此处会浏览器检查ajax调用url是否原站点旗下
        } catch (E) {
            alert(E);
            return false;
        }

        // CurrentXmlHttp = req;  // 保存当前req到全局变量，利于Abort等操作。

        // 开始超时计数
        CurrentTimerId = setTimeout(StopDownloadByTimeOut, parseInt(document.getElementById(MaxTimeout_ID).value) * 1000);

        start = new Date();
        startT = start.getTime();

        message = start.toLocaleTimeString() + " [UL/DL]=[" + UploadLengthKByte + "/" + DownloadLengthKByte + "]KB  ";
        if (ie) logoutput.value += message;
        else logoutput.value += message;

        DownloadProgressLock = true;
        msecond.innerHTML = "...";
        speed.innerHTML = "...";

        // ButtonUnitTest.disabled = DownloadProgressLock;
        ButtonUnitTest.value = BatchCmdText[4];
        ButtonUnitTest.onclick = BatchCmdScript[4];

        // 设置下载/上传大小为只度
        if (ie) {
            UploadLength.readOnly = "readonly";
            DownloadLength.readOnly = "readonly";
        } else {
            UploadLength.readOnly = DownloadProgressLock;
            DownloadLength.readOnly = DownloadProgressLock;
        }

        //req.send(null);  // GET
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        req.send('DownloadLength=' + DownloadLengthKByte + '&UploadData=' + SendData);
    }
    return true;
}




function statechange_callback() {
    var message;
    var logoutput = document.getElementById(LogOutput_ID);
    var loadedT;
    var ButtonUnitTest = document.getElementById(ButtonUnitTest_ID);
    var DownloadLength = document.getElementById(DownloadLength_ID);
    var UploadLength = document.getElementById(UploadLength_ID);

    var DownloadLengthKByte = Math.min(100000, parseInt(DownloadLength.value, 10));    // 下载大小，千字节
    var UploadLengthKByte = Math.min(5000, parseInt(UploadLength.value, 10));    // 下载大小，千字节
    var msecond = document.getElementById(msecond_id);
    var speed = document.getElementById(speed_id);

    switch (req.readyState) {
        case 3: // Interacting
            InteractingCount++;
            // 影响性能 for Firefox,因此人为将选项提前。
            //var end=new Date(); //因此把时间类 定义移到各个case中
            //message = (end.getTime()-startT)+"(ms) "+"AJAX Interactive";
            //if(ie) logoutput.value += message + "\r\n";
            //else logoutput.innerHTML += message + "\n";
            break;
        case 0: // Not Init
            var end = new Date();
            //msecond.innerHTML = "";
            message = "S0=" + (end.getTime() - startT) + "ms ";
            if (ie) logoutput.value += message;
            else logoutput.value += message;
            break;
        case 1: // Loading
            var end = new Date();

            // IE will run this twice, both time the startT is null

            if (startT != null) {
                message = "S1=" + (end.getTime() - startT) + "ms ";
                if (ie) logoutput.value += message;
                else logoutput.value += message;
            }
            break;
        case 2: // Loaded
            var end = new Date();
            loadedT = end.getTime();
            message = "S2=" + (loadedT - startT) + "ms ";
            if (ie) logoutput.value += message;
            else logoutput.value += message;
            break;
        case 4: // Completed
            var end = new Date();
            var endT = end.getTime();
            var diff;
            var TrueDownloadLengthByte;

            // loadedT 是指数据上传所需时间，Opera不支持
            // diff = opear?(endT - startT):(endT-loadedT);  // For Opear

            //if(opear)
            //{
            //diff = endT - startT; // in mili second
            //}
            //else
            //{
            diff = endT - startT;
            if (UploadLengthKByte == 0 && endT > loadedT) diff = endT - loadedT;
            if (DownloadLengthKByte == 0 && loadedT > startT) diff = loadedT - startT;
            //}

            // 停止超时计时
            if (CurrentTimerId) {
                clearTimeout(CurrentTimerId);
                CurrentTimerId = null;
            };

            message = "S3=" + InteractingCount + "(s) ";  // Count Interacting
            message += "S4=" + (endT - startT) + "ms  ";

            DownloadProgressLock = false;
            // ButtonUnitTest.disabled = DownloadProgressLock;
            ButtonUnitTest.value = BatchCmdText[3];
            ButtonUnitTest.onclick = BatchCmdScript[3];

            // 设置下载/上传大小为可更改，这里不用区分浏览器了？
            UploadLength.readOnly = DownloadProgressLock;
            DownloadLength.readOnly = DownloadProgressLock;


            try { if (req.status); } catch (E) {
                return;
            }
            //对于Firefox，Abort后会引发一次状态更新
            // 但如果此时上传没有做完，则会导致读取req.status值引发内部错误。

            // 读取真实下载大小
            TrueDownloadLengthByte = parseInt(req.responseText.length);
            if (DownloadLengthKByte * 1024 != TrueDownloadLengthByte)
                message += "responseText.length=" + TrueDownloadLengthByte + "  ";

            switch (req.status) {
                case 200:
                    var speedText;

                    msecond.innerHTML.value = "";
                    speed.innerHTML.value = "";
                    if (diff > 0) {
                        var speed_item = new Array();
                        msecond.innerHTML = Math.floor(diff) / 1000 + "s";
                        // message += diff + "ms Total, ";
                        var DL_Speed = 1000 * (TrueDownloadLengthByte / 1024 + UploadLengthKByte) / diff; // KByte/s

                        speed_item.push(startT);    //开始时间milisecond(UNIX Time)
                        speed_item.push(TrueDownloadLengthByte / 1024);    //下载大小KByte
                        speed_item.push(UploadLengthKByte);    //上传大小KByte
                        speed_item.push(diff);    //耗时millisecond
                        speed_item.push(DL_Speed);    //速度 KByte/s
                        ScoreArray.push(speed_item);

                        if (DL_Speed > 1024)
                            speedText = Math.floor(DL_Speed) / 1000 + "MB/s";
                        else
                            speedText = Math.floor(DL_Speed * 1000) / 1000 + "KB/s";

                        speed.innerHTML = speedText;
                        message += speedText + "  ";
                        LastSpeed = DL_Speed;
                        LastTimeCost = diff;

                    } else {
                        msecond.innerHTML = diff + "ms";
                        speed.innerHTML = "下载时间太短，无法测出速度。";
                        message += " Infinite Speed";
                        LastSpeed = Number.POSITIVE_INFINITY;
                        LastTimeCost = diff;
                    }
                    break;
                case 304:
                    msecond.innerHTML = "";
                    speed.innerHTML = "内容从缓冲获得，无法计算下载速度。";
                    message += " NaN Speed, Http/" + req.status;
                    LastSpeed = Number.NaN;
                    LastTimeCost = 0;
                    break;
                case 404:
                    msecond.innerHTML = "";
                    speed.innerHTML = "流量发送程序不存在，请联系网站管理员检查配置。";
                    message += " NaN Speed, Http/" + req.status;
                    LastSpeed = Number.NaN;
                    LastTimeCost = Number.POSITIVE_INFINITY;
                    break;
                default:
                    msecond.innerHTML = "";
                    speed.innerHTML = "下载内容状态错误：" + req.status;
                    message += " NaN Speed, Http/" + req.status;
                    LastSpeed = Number.NaN;
                    LastTimeCost = Number.POSITIVE_INFINITY;
                    break;
            } // End Of switch

            // Write Log to textarea
            if (ie) logoutput.value += message + "\r\n";
            else logoutput.value += message + "\n";

            // Clean Up , prevent memory leak
            delete req.onreadystatechange;

            req = null; // 本地XmlHttp清零，已改为全局变量
            // CurrentXmlHttp = null; // 全局XmlHttp 指针清零。

            startT = null;

            // 如果批量测试在进行，则继续
            if (BatchTestInProgressLock) {
                AutomaticTestLoop();
            }

            break;
        default:
            msecond.innerHTML = "";
            speed.innerHTML = "Unknown AJAX State:" + req.readyState;
            break;
    }
}




// 强制停止下载，可能因用户手触或时间超时（或者考虑这两者分开写函数？）
function StopDownloadByTimeOut() {
    StopDownload(2);
}

function StopDownloadByUser() {
    StopDownload(4);
}

function StopDownload(ReasonInt) {
    // 停止超时计数
    if (CurrentTimerId) {
        clearTimeout(CurrentTimerId);
        CurrentTimerId = null;
    }

    // 恢复单次测试提示和相关对话框
    var ButtonUnitTest = document.getElementById(ButtonUnitTest_ID);
    ButtonUnitTest.value = BatchCmdText[3];
    ButtonUnitTest.onclick = BatchCmdScript[3];

    document.getElementById(UploadLength_ID).readOnly = false;
    document.getElementById(DownloadLength_ID).readOnly = false;

    var message = "";
    var logoutput = document.getElementById(LogOutput_ID);
    message = UnitTestNoticeText[ReasonInt];

    if (ie) logoutput.value += message + "\r\n";
    else logoutput.value += message + "\n";

    document.getElementById(speed_id).innerHTML = '<SPAN style="color: red;">' + UnitTestNoticeText[ReasonInt] + '</SPAN>';
    document.getElementById(msecond_id).innerHTML = "";

    // 实施关闭
    if (req) {
        delete req.onreadystatechange; // 放在abort后引起Firefox报错，声称req无此属性
        req.abort(); // XmlHttp 下载停止，不知是否会引发状态变更 再次调用完成的问题
        req = null;
    }

    // 如果在批量测试中，修改相关提示...
    if (BatchTestInProgressLock)
        AutomaticTestStop(ReasonInt);

    DownloadProgressLock = false; //关闭并发锁
}


// 清空结果数据矩阵集
function ClearScoreArray() {
    var speed_item, key;
    // ScoreArray
    // 迭代属性。
    for (speed_item in ScoreArray) {
        for (key in speed_item) {
            delete key;
        }
        delete speed_item;
    }
    ScoreArray = null;
    ScoreArray = new Array(); ;
}

function AutomaticTestInit() {
    var i;
    var logoutput = document.getElementById(LogOutput_ID);
    var message = "";
    var start = new Date();


    //if(ie) logoutput.value += message + "\r\n";
    //else logoutput.innerHTML += message + "\n";
    message = start.toLocaleTimeString() + " " + "Batch Test Start";
    if (ie) logoutput.value += message + "\r\n";
    else logoutput.value += message + "\n";

    // 生成分组数据包大小数据
    LengthArray = new Array();
    LengthArray[0] = 16;
    for (i = 1; i < 8; i++)
        LengthArray[i] = LengthArray[i - 1] * 2;

    // 需要清空结果数据？ 或 Output Log
    ClearScoreArray();
    LastTimeCost = 0;

    // 需要设置说明 循环测试在进行中，不要进行其它键盘/鼠标/网络操作。
    document.getElementById(BatchDownloadNoticer_ID).innerHTML = NoticeText[1];
    document.getElementById(ButtonBatchTest_ID).value = BatchCmdText[2];
    document.getElementById(ButtonBatchTest_ID).onclick = BatchCmdScript[2];
    BatchTestInProgressLock = true;

    // 并关闭原有测试结果图？
    var historyGraph = document.getElementById(historyGraph_ID);
    //historyGraph.style.visibility = "hidden";
    historyGraph.style.display = "none";

    // 最初的测试操作
    NextOperation = 1;

    // 清空Cookie
    document.cookie = "";

    // 设置数组最大大小；
    LengthArray_MaxLength = LengthArray.length;
    ShowProgressBar();

    AutomaticTestLoop();
}


function AutomaticTestStopByUser() {
    AutomaticTestStop(4);
}

// 设置测试中止标志
function AutomaticTestStop(ReasonInt) {
    // 需要设置说明 循环测试在进行中，不要进行其它键盘/鼠标/网络操作。
    var start = new Date();
    var logoutput = document.getElementById(LogOutput_ID);
    document.getElementById(BatchDownloadNoticer_ID).innerHTML = NoticeText[ReasonInt];
    document.getElementById(ButtonBatchTest_ID).value = BatchCmdText[1];
    document.getElementById(ButtonBatchTest_ID).onclick = BatchCmdScript[1];
    BatchTestInProgressLock = false;
    var message = start.toLocaleTimeString() + " " + NoticeText[ReasonInt]; // "Batch Test End by Timeout "+document.getElementById(MaxTimeout_ID).value+"s";
    if (ReasonInt == 2) message += "(" + document.getElementById(MaxTimeout_ID).value + "s)";
    if (ie) logoutput.value += message + "\r\n";
    else logoutput.value += message + "\n";

    HideProgressBar();

    // 获取新测试图结果
    DisplayGraph();
    ClearScoreArray();
}

function AutomaticTestLoop() {
    //检查LengthArray是否有数
    if (LengthArray.length > 0) {
        //     生成测试请求
        var ObjDownloadLength = document.getElementById(DownloadLength_ID);
        var ObjUploadLength = document.getElementById(UploadLength_ID);
        var BatchTestType = document.getElementById(BatchTestType_ID);
        var BatchTestTypeInt = parseInt(BatchTestType.value);

        if (NextOperation <= 1) {   // 下载
            if ((BatchTestTypeInt & 1) == 1) {
                ObjDownloadLength.value = LengthArray[0];
                ObjUploadLength.value = 0;
                NextOperation = 1;
            } else {
                NextOperation = 2;
            }
        }

        if (NextOperation >= 2) {   // 上传
            NextOperation = 2;
            if ((BatchTestTypeInt & 2) == 2) {
                ObjDownloadLength.value = 0;
                ObjUploadLength.value = LengthArray[0];
            } else {   //例外的情况不应该发生，要在后面判断避免。
                window.alert("BatchTestTypeInt&2=" + BatchTestTypeInt & 2);
            }

        }

        // 如果请求成功，
        if (download()) {
            // 如果是测试组最后一项测试，则删除请求数组对应值
            if (NextOperation >= 2 || (BatchTestTypeInt & 2) != 2) {
                LengthArray.shift();  // 删除首数据
                NextOperation = 1;
                //UpdateProgressBar(Math.floor(100*(1-LengthArray.length/LengthArray_MaxLength)));
                UpdateProgressBar(Math.floor(100 * ((Math.pow(1.5, LengthArray_MaxLength - LengthArray.length) - 1) / (Math.pow(1.5, LengthArray_MaxLength) - 1))));
            }
            // 否则则进行同组下一项测试
            else
                NextOperation = 2;
        }
        //     并设置超时时间重执行本函数做检查。
        // pause(100);
        // 改在download 函数回调函数中作检查。
    }
    else {
        // 如果没有进一步的数据，则证明循环检测完成。清除各种说明，并发送测试图像请求。
        var message, logoutput = document.getElementById(LogOutput_ID);
        var start = new Date();
        document.getElementById(BatchDownloadNoticer_ID).innerHTML = NoticeText[3];

        message = start.toLocaleTimeString() + " " + "Batch Test End Successful ";
        if (ie) logoutput.value += message + "\r\n";
        else logoutput.value += message + "\n";

        BatchTestInProgressLock = false;
        document.getElementById(ButtonBatchTest_ID).value = BatchCmdText[1];
        document.getElementById(ButtonBatchTest_ID).onclick = BatchCmdScript[1];

        HideProgressBar();

        // 获取新测试图结果
        DisplayGraph();
        ClearScoreArray();
    }
}


function HideProgressBar() {
    var progress_contain = document.getElementById(progress_contain_ID);
    progress_contain.style.display = "none";
}

function ShowProgressBar() {
    var progress_contain = document.getElementById(progress_contain_ID);
    progress_contain.style.display = "block";

    var progress_bar = document.getElementById(progress_bar_ID);
    progress_bar.style.display = "block";
    progress_bar.style.left = '0%';
    progress_bar.style.width = '0%';
}

function UpdateProgressBar(percent) {
    var progress_bar = document.getElementById(progress_bar_ID);
    progress_bar.style.left = '0%';
    progress_bar.style.width = percent + '%';
}


function DisplayGraph() {
    //historyGraph.style.visibility = "visable";
    //将数据数组序列化， 源{1,2|3,4|5,6|7,8}
    // 新列队{下载大小,上传大小,耗时|,,|,,|...} 由绘图程序来重组
    var ScoreArraySeq = "", i = 0, tempArray = new Array();
    var GraphURL = "zedGraph.aspx";
    var historyGraph = document.getElementById(historyGraph_ID);

    for (i = 0; i < ScoreArray.length; i++) {//大小KByte , 耗时millisecond
        tempArray[i] = ScoreArray[i][1] + "," + ScoreArray[i][2] + "," + ScoreArray[i][3];
    }

    ScoreArraySeq = tempArray.join("|");

    // 原有AJAX获取图片内容方式不合适，因为 img src只接受get方式。
    // 因此改用Cookie来传。
    var start = new Date();
    GraphID = Math.floor(Math.random() * start.getTime());
    document.cookie = GraphID + "=" + ScoreArraySeq;

    //显示获取图片的提示文字
    historyGraph.alt = DownloadIMGText[1];
    //historyGraph.style.visibility = "visible";
    historyGraph.style.display = "";

    //改变图片链接地址。
    historyGraph.src = GraphURL + "?graphid=" + GraphID;

    setTimeout(deleteCookieGraphID, 3000);

}

function deleteCookieGraphID() {
    var historyGraph = document.getElementById(historyGraph_ID);
    if (historyGraph.complete) {
        historyGraph.alt = DownloadIMGText[5];
        deleteCookie(GraphID);
    }
    else {
        setTimeout(deleteCookieGraphID, 3000);
    }
}

function LogClear() {
    var logoutput = document.getElementById(LogOutput_ID);
    logoutput.value = "";
    writelog();
}

function LogDisplay() {
    var Text = new Array("隐藏日志", "显示日志");
    var logoutput = document.getElementById(LogOutput_ID);
    var HrefDisplayLog = document.getElementById(HrefDisplayLog_ID);
    /*
    if(logoutput.style.visibility != "visible")
    {
    logoutput.style.visibility = "visible";
    HrefDisplayLog.innerHTML = Text[0];
    }
    else
    {
    logoutput.style.visibility = "hidden";
    HrefDisplayLog.innerHTML = Text[1];
    }
    */
    if (logoutput.style.display != "") {
        logoutput.style.display = "";
        HrefDisplayLog.innerHTML = Text[0];
    }
    else {
        logoutput.style.display = "none";
        HrefDisplayLog.innerHTML = Text[1];
    }

}

function deleteCookie(name) {
    document.cookie = name + "=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT";
    document.cookie = name + "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function bodyload() {
    writelog();
    window.alert("版本:" + version + "\n本测试模拟用户PC到Web服务器不同数据大小的上传下载速度。\n测试数据包越大测试结果越稳定。");
}

function writelog() {
    var logoutput = document.getElementById(LogOutput_ID);
    var message = "";

    message += "userIP=" + document.getElementById(userip_ID).innerHTML;
    if (ie) message += "\r\n";
    else message += "\n";

    message += "browser=" + document.getElementById(browser_ID).innerHTML;
    if (ie) message += "\r\n";
    else message += "\n";

    message += "system=" + document.getElementById(system_ID).innerHTML;
    if (ie) message += "\r\n";
    else message += "\n";

    if (ie) logoutput.value += message;
    else logoutput.value += message;

}

function testXMLHttpRequest() {
    var NativeXMLHttpRequest = document.getElementById(NativeXMLHttpRequest_ID);

    var msxmls = new Array(
      'Msxml2.XMLHTTP.6.0',
      'Msxml2.XMLHTTP.5.0',
      'Msxml2.XMLHTTP.4.0',
      'Msxml2.XMLHTTP.3.0',
      'Msxml2.XMLHTTP.2.6',
      'Msxml2.XMLHTTP',
      'Microsoft.XMLHTTP.1.0',
      'Microsoft.XMLHTTP.1',
      'Microsoft.XMLHTTP');

    if (window.XMLHttpRequest) {
        NativeXMLHttpRequest.innerHTML = "Y";
    } else {
        NativeXMLHttpRequest.innerHTML = "N";
    }

    if (window.ActiveXObject) {
        for (var i = 0; i < msxmls.length; i++) {
            try {
                var a = new ActiveXObject(msxmls[i]);
                a = null;
                document.getElementById(msxmls[i]).innerHTML = "Y";
            } catch (e) {
                document.getElementById(msxmls[i]).innerHTML = "N";
            }
        }
    } else {
        for (var i = 0; i < msxmls.length; i++) {
            document.getElementById(msxmls[i]).innerHTML = "N";
        }
    }
}



// 全局语句
if (msieversion() > 0) ie = true;
KiloByte = "A"; for (var i = 0; i < 10; i++) KiloByte += KiloByte;
KiloByteTimes256 = KiloByte; for (var i = 0; i < 8; i++) KiloByteTimes256 += KiloByteTimes256;
// alert(KiloByte.length);